﻿using System;
using System.Data;
using System.Collections.Generic;
using eTMS.Controllers.GiayToSinhVienService;
namespace eTMS.Controllers{
public class GiayToSinhVienControllerBase : CommonController{
	public GiayToSinhVienControllerBase()
		: base()
	{	
		this.dao = new GiayToSinhVienServiceClient();
	}
	~GiayToSinhVienControllerBase(){
		if(dao.State==System.ServiceModel.CommunicationState.Opened)try{dao.Close();}catch{}
	}
	private DataTable _Table;
	private GiayToSinhVienEntity oGiayToSinhVien;	
	public GiayToSinhVienEntity GiayToSinhVienObject{
		get{
			return oGiayToSinhVien;
		}
		set{
			oGiayToSinhVien=value;
		}
	}
	protected GiayToSinhVienServiceClient dao;
	public DataTable Table{
		get{
			return _Table;
		}
        set
        {
            _Table = value;
        }
	}
	public void AddIndexToTable(){
		this.AddIndexToTable(_Table);
	}
	public void ResetTableIndex(){
		this.ResetTableIndex(_Table);
	}
	public bool AddNew(){
		if(oGiayToSinhVien==null)return false;
		bool result=true;
		try{
			oGiayToSinhVien = dao.SaveRet(oGiayToSinhVien);
		}
		catch{
			result=false;
		}
		return result;
	}
	public bool Update(){
		if(oGiayToSinhVien==null)return false;
		return dao.Update(oGiayToSinhVien);
	}
	public bool Delete(){
		if(oGiayToSinhVien==null)return false;
		bool retvalue = dao.Delete(oGiayToSinhVien);
		return retvalue;
	}
	public bool DeleteByID(Int32 GiayToSinhVien_ID){
		bool retvalue = dao.DeleteByID(GiayToSinhVien_ID);		
		return retvalue;
	}
	public void ResetObject(){
		this.oGiayToSinhVien = new GiayToSinhVienEntity();
	}
    //Copy data from data row in grid to object
    public GiayToSinhVienEntity MapDataRowToObject(DataRow row){
		GiayToSinhVienEntity o = new GiayToSinhVienEntity();
		 if(!row.IsNull("SoLuong"))
			o.SoLuong=ConvertInt(row["SoLuong"]);
		 if(!row.IsNull("LoaiGiayTo_ID"))
			o.LoaiGiayTo_ID=(Int32)(row["LoaiGiayTo_ID"]);
		 if(!row.IsNull("SinhVien_ID"))
			o.SinhVien_ID=(Int32)(row["SinhVien_ID"]);
		 if(!row.IsNull("GiayToSinhVien_ID"))
		    o.GiayToSinhVien_ID=(Int32)(row["GiayToSinhVien_ID"]);
         if (!row.IsNull("GhiChu"))
             o.GhiChu = row["GhiChu"].ToString();
         if (!row.IsNull("DaTra"))
             o.DaTra = ConvertBool(row["DaTra"]);
         if (!row.IsNull("NgayTra"))
             o.NgayTra = ConvertDateTime(row["NgayTra"]);
         else
             o.NgayTra = DateTime.Now;
		 return o;
    }
	//Copy data from object to data row in grid    
    public void MapObjectToDataRow(GiayToSinhVienEntity o,DataRow row){
		row["SoLuong"]=o.SoLuong;
		row["LoaiGiayTo_ID"]=o.LoaiGiayTo_ID;
		row["SinhVien_ID"]=o.SinhVien_ID;
		row["GiayToSinhVien_ID"]=o.GiayToSinhVien_ID;
        row["GhiChu"] = o.GhiChu;
        row["DaTra"] = o.DaTra;
        row["NgayTra"] = o.NgayTra;
    }
    public void MapObjectToDataRow(DataRow row){
		this.MapObjectToDataRow(this.GiayToSinhVienObject,row);
    }
	
}
}
